package simulator;

import simulator.parser.XmlParser;
import simulator.eventHandler.*;

public class Test {
	public static void main(String[] args) throws Exception {
		int count = Integer.parseInt(args[0]);
		int unAvailableCount = 0;
		int unDurableCount = 0;
		for (int i = 0; i < count; i++) {
			Unit root = XmlParser.readFile("test.xml");
			EventQueue events = new EventQueue();
			root.generateEvents(events, 0, Configuration.totalTime, true);
			Event[] eventsArray = events.convertToArray();
			System.out.println("event queue size=" + eventsArray.length);
			// events.printAll();
			EventHandler handler = new RandomDistributeEventHandler2();
			handler.start(root);
			int index = 0;
			for (Event e : eventsArray) {

				handler.handleEvent(e);
				index++;
				// if(index%1000==0)
				// System.out.println("Processed "+index);
			}
			Result result = handler.end();
			System.out.println(result);
			unAvailableCount+=result.unAvailableCount;
			unDurableCount+=result.unDurableCount;
		}
		System.out.println("avg unavailable="+(double)unAvailableCount/(double)count);
		System.out.println("avg undurable="+(double)unDurableCount/(double)count);
	}
}
